package com.zyh.system.supermark1.dao.impl;

import com.zyh.system.supermark1.dao.UserDao;
import com.zyh.system.supermark1.db.BaseDAO;
import com.zyh.system.supermark1.domain.User;

import java.util.List;

public class UserDaoImpl implements UserDao {

    // 查询指定的用户信息
    @Override
    public User find(String userName) {
        String sql = "select * from user where userName=?";
        List<User> users = BaseDAO.selectData(sql, User.class, userName);
        if (users.size() != 0) {
            return users.get(0);
        }
        return null;
    }

    // 注册
    @Override
    public int register(User user) {
        String sql = " insert into user value(null,?,?,?,?)";
        return BaseDAO.changeOneData(sql, user.getUserName(), user.getPassWord(), user.getOtherName(), user.getAge());
    }

    // 登录
    public List<User> login(User user) {
        String sql = " select * from user where userName=? and passWord = ?";
        return BaseDAO.selectData(sql, User.class, user.getUserName(), user.getPassWord());
    }
}